//
//  TopicTableContentView.m
//  TipsProject
//
//  Created by Suny on 15/5/19.
//  Copyright (c) 2015年 Suny. All rights reserved.
//


#define kImageViewSize 40
#import "TopicTableContentView.h"
#import "UIImageView+WebCache.h"
@implementation TopicTableContentView

- (id)initWithFrame:(CGRect)frame
{
	self = [super initWithFrame:frame];
	if (self)
	{
		self.backgroundColor = [UIColor colorWithHexString:@"ebebeb"];
		[self addSubview:self.imageViewBorder];
		[self addSubview:self.imageView];
		[self addSubview:self.topicNameLabel];
	}
	
	return self;
}


- (UIImageView *)imageView
{
	if (!_imageView)
	{
		_imageView = [[UIImageView alloc] initWithFrame:CGRectZero];
	}
	return _imageView;
}

- (UIImageView *)imageViewBorder
{
	if (!_imageViewBorder)
	{
		_imageViewBorder = [[UIImageView alloc] initWithFrame:CGRectZero];
		_imageViewBorder.image = [UIImage imageNamed:@"sub_topic_background"];
	}
	return _imageViewBorder;
}


- (UILabel *)topicNameLabel
{
	if (!_topicNameLabel) 
	{
		_topicNameLabel = [[UILabel alloc] initWithFrame:CGRectZero];
		_topicNameLabel.backgroundColor = [UIColor clearColor];
//		_topicNameLabel.font = [UIFont systemFontOfSize:24];
	}
	return _topicNameLabel;
}


- (void)updateDisplayInfo:(TopicTableDisplayInfo *)displayInfo
{
	self.topicNameLabel.text = displayInfo.topicInfo.name;
	
	self.displayInfo = displayInfo;
	self.topicNameLabel.textAlignment = NSTextAlignmentLeft;

	if (displayInfo.style == TopicTableViewCellContentDefaultStyle) 
	{
		self.topicNameLabel.textColor = [UIColor blackColor];
		self.topicNameLabel.font = [UIFont systemFontOfSize:20];
	}
	else
	{
		self.topicNameLabel.textColor = [UIColor colorWithHexString:@"8a8a8a"];
	}
	
}

- (void)layoutSubviews
{
	[super layoutSubviews];
	self.backgroundColor = [UIColor clearColor];
	self.topicNameLabel.textAlignment = NSTextAlignmentLeft;
	self.imageViewBorder.hidden = YES;

	
	if (((TopicTableDisplayInfo *)self.displayInfo).style == TopicTableViewCellContentDefaultStyle )
	{
		self.imageView.frame = CGRectMake(10, 10, kImageViewSize *2, self.height - 20);
		self.topicNameLabel.frame = CGRectMake(self.imageView.right + 50, 0, 200, 30);
		self.topicNameLabel.centerY = (CGFloat) (self.height/2.0);

	}
	else      if (((TopicTableDisplayInfo *)self.displayInfo).style == TopicTableViewCellContentSubStyle )
	{
		self.imageViewBorder.hidden = NO;
		self.imageViewBorder.frame = CGRectMake(15, 7, 106, 105);
		self.imageViewBorder.right = self.width - 7;

		
		self.imageView.frame = CGRectMake(15, 15, 90, 65);
		self.topicNameLabel.textAlignment = NSTextAlignmentCenter;


		self.imageView.right = self.width - 15;
		self.topicNameLabel.frame = CGRectMake(self.imageView.left ,self.imageView.bottom + 5, self.imageView.width, 20);
		self.backgroundColor = [UIColor colorWithHexString:@"b0b0b0"];

	}

    else if (((TopicTableDisplayInfo *)self.displayInfo).style == TopicTableViewCellContentSubStyle1 )
    {
        self.imageView.frame = CGRectInset(self.bounds, 5, 5);

        self.topicNameLabel.frame = CGRectMake(self.imageView.left ,self.imageView.bottom - 20, self.imageView.width, 20);
		self.topicNameLabel.backgroundColor = [UIColor colorWithPatternImage:[[UIImage imageNamed:@"topic_name_background"] 
																			  resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)]];
    }
	
	[self.imageView setQNImageWithURL:[NSURL URLWithString:((TopicTableDisplayInfo *)self.displayInfo).topicInfo.thumbnail]
					 placeholderImage:[UIImage imageNamed:@"default_1"]];

	
}

@end
